package com.linkage.jz.bankruptcy.activity.Project;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.database.Cursor;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Color;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.ColorDrawable;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.os.Environment;
import android.os.Handler;
import android.os.Message;
import android.provider.MediaStore;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.telephony.TelephonyManager;
import android.text.Editable;
import android.text.TextUtils;
import android.text.TextWatcher;
import android.util.Log;
import android.view.Gravity;
import android.view.KeyEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.view.animation.AnimationUtils;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.PopupWindow;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.google.gson.Gson;
import com.google.gson.JsonObject;
import com.linkage.jz.bankruptcy.BankruptcyApp;
import com.linkage.jz.bankruptcy.Consts;
import com.linkage.jz.bankruptcy.R;
import com.linkage.jz.bankruptcy.activity.Main.RateCalcActivity;
import com.linkage.jz.bankruptcy.activity.MainActivity;
import com.linkage.jz.bankruptcy.activity.Person.PersonSettingActivity;
import com.linkage.jz.bankruptcy.activity.RegistLogin.GetPwdOneActivity;
import com.linkage.jz.bankruptcy.activity.RegistLogin.PhoneLoginActivity;
import com.linkage.jz.bankruptcy.adapter.FullyGridLayoutManager;
import com.linkage.jz.bankruptcy.adapter.GridImageAdapter;
import com.linkage.jz.bankruptcy.base.BaseActivity;
import com.linkage.jz.bankruptcy.base.BaseCreateActivity;
import com.linkage.jz.bankruptcy.bean.LoginInfo;
import com.linkage.jz.bankruptcy.bean.MyProInfo;
import com.linkage.jz.bankruptcy.bean.TokenInfo;
import com.linkage.jz.bankruptcy.event.MovePicEvent;
import com.linkage.jz.bankruptcy.event.RefreshEvent;
import com.linkage.jz.bankruptcy.net.BaseSubscriber;
import com.linkage.jz.bankruptcy.net.Network;
import com.linkage.jz.bankruptcy.net.ToastUtil;
import com.linkage.jz.bankruptcy.utils.SPUtils;
import com.linkage.jz.bankruptcy.utils.SignUtil;
import com.linkage.jz.bankruptcy.widget.CommonPromptDialog;
import com.linkage.jz.bankruptcy.widget.PublicNoticeDialog;
import com.linkage.jz.bankruptcy.widget.ShapeLoadingDialog;
import com.linkage.jz.bankruptcy.widget.datepicker.CustomDatePicker;
import com.linkage.jz.bankruptcy.widget.datepicker.DateFormatUtils;
import com.linkage.seapeak.activity.user.ImageShowActivity;
import com.linkage.seapeak.pojo.UploadImage;

import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.GregorianCalendar;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Random;
import java.util.concurrent.TimeUnit;

import cn.sharesdk.framework.Platform;
import cn.sharesdk.framework.PlatformActionListener;
import cn.sharesdk.framework.ShareSDK;
import cn.sharesdk.tencent.qq.QQ;
import okhttp3.Call;
import okhttp3.Callback;
import okhttp3.FormBody;
import okhttp3.Headers;
import okhttp3.MediaType;
import okhttp3.MultipartBody;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.RequestBody;
import okhttp3.Response;
import rx.Observable;
import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;
import top.zibin.luban.CompressionPredicate;
import top.zibin.luban.Luban;
import top.zibin.luban.OnCompressListener;


/**
 * A login screen that offers login via email/password.
 */
public class CreateProjectDetailActivity extends BaseCreateActivity implements OnClickListener {
    private static final String TAG = CreateProjectDetailActivity.class.getSimpleName();
    private PublicNoticeDialog noticeDialog;
    private ShapeLoadingDialog shapeLoadingDialog;

    private List<UploadImage> mImgList = new ArrayList<>();
    private GridImagesAdapter adapter;
    private RecyclerView mRecyclerView;
    private RelativeLayout rl_addlogo;
    private int maxSelectNum = 1;
    //    private PopupWindow pop;
    private CustomDatePicker mTimerPicker;

    @Override
    public void initData() {

    }

    @Override
    public void setListener() {
        top_mune1.setOnClickListener(this);
        top_mune2.setOnClickListener(this);
        top_back.setOnClickListener(this);
//        rl_addlogo.setOnClickListener(this);
    }

    @Override
    public void initTitle() {
        top_title = findViewById(R.id.top_title);
        if (m_addtype == 1) {
            top_title.setText("新建项目");
        } else {
            top_title.setText("编辑项目");
        }
//        top_mune.setVisibility(View.INVISIBLE);
    }

    @Override
    public void initView() {

    }

    ImageView mLeftLogo;
    ImageView mRightLogo;
    private EditText et_debtorName, et_projectName, et_projectLogo, et_projectNote;
    private TextView tv_projectType,item_other0,tv_projectName,tv_projectNote;
    private RelativeLayout rl_projectType;
    Button btn_login;
    TextView top_title, getPwd;
    Button top_back;
    TextView top_mune1, top_mune2;
    CheckBox ck_remember;
    private int protype;
    private static int m_addtype = 1;//1新增 2修改
    LinearLayout ll_charger, ll_admin, qqlogin;
    private static MyProInfo mInfo;

    public static void start(Context context, MyProInfo info, int type) {
        Intent intent = new Intent(context, CreateProjectDetailActivity.class);
        mInfo = info;
        m_addtype = type;
        context.startActivity(intent);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {

        setContentView(R.layout.activity_create_pro_detail);

        initview();
        initWidget();

        shapeLoadingDialog = new ShapeLoadingDialog(this);


        super.onCreate(savedInstanceState);
        EventBus.getDefault().register(this);
    }

    @Subscribe
    public void onEventMainThrend(MovePicEvent event) {
        String msg = event.getMsg();
//        rl_addlogo.setVisibility(View.VISIBLE);
    }


    protected void onDestroy() {
        super.onDestroy();
        EventBus.getDefault().unregister(this);
    }

    String strType = "";

    //初始化视图
    private void initview() {
        //登录层、下拉层、其它登录方式层


        top_back = findViewById(R.id.top_back);
        top_mune1 = findViewById(R.id.top_mune1);
        top_mune2 = findViewById(R.id.top_mune2);
        et_debtorName = findViewById(R.id.et_debtorName);
        et_projectName = findViewById(R.id.et_projectName);
//        et_projectLogo = findViewById(R.id.et_projectLogo);
        et_projectNote = findViewById(R.id.et_projectNote);
        tv_projectType = findViewById(R.id.tv_projectType);

        mRecyclerView = findViewById(R.id.recycler);
//        rl_addlogo = findViewById(R.id.rl_addlogo);
        et_debtorName.setText(mInfo.getDebtorName());

        et_projectName.setText(mInfo.getProjectName());
//        et_projectLogo.setText(mInfo.getProjectLogo());
        et_projectNote.setText(mInfo.getProjectNote());
        item_other0 = findViewById(R.id.item_other0);
        tv_projectName = findViewById(R.id.tv_projectName);
        tv_projectNote = findViewById(R.id.tv_projectNote);
        protype = -1;
        final String[] strTypes = {"破产清算", "破产重整", "破产和解"

                , "其他"};
//        if (!"".equalsIgnoreCase(proType)) {
//            protype = Integer.parseInt(proType);
//            tv_projectType.setText(strTypes[protype]);
//
//        }
//        else {
//            protype = 0;
//            tv_projectType.setText("破产清算");
//        }

        et_debtorName.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {
            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {
//                        textView.setText(s.toString());
                et_projectName.setText(s.toString()+strType+"案");
                item_other0.setText(s.length() + "/40");
            }

            @Override
            public void afterTextChanged(Editable s) {
            }
        });


        et_projectNote.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {
            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {
//                        textView.setText(s.toString());
//                et_projectName.setText(s.toString()+strType+"案");
                tv_projectNote.setText(s.length() + "/800");

            }

            @Override
            public void afterTextChanged(Editable s) {
            }
        });

        et_projectName.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {
            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {
//                        textView.setText(s.toString());
//                et_projectName.setText(s.toString()+strType+"案");
                tv_projectName.setText(s.length() + "/60");
            }

            @Override
            public void afterTextChanged(Editable s) {
            }
        });
        //    设置一个下拉的列表选择项


        rl_projectType = findViewById(R.id.rl_projectType);

        if (m_addtype == 2) {
            top_mune2.setVisibility(View.INVISIBLE);
        }
        rl_projectType.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {

                final List<String> values = new ArrayList<String>();

                AlertDialog.Builder builder = new AlertDialog.Builder(CreateProjectDetailActivity.this);

                //builder.setIcon(R.drawable.ic_launcher);
                builder.setTitle("请选择");
                //    指定下拉列表的显示数据
                final String[] strTypes = {"破产清算", "破产重整", "破产和解"

                        , "其他"};
                //    设置一个下拉的列表选择项
                builder.setItems(strTypes, new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        tv_projectType.setText(strTypes[which]);

                        protype = which;
                        strType = strTypes[protype];
                        et_projectName.setText(et_debtorName.getText().toString()+strType+"案");
                        vName();
                    }
                });
                builder.show();

            }
        });

    }
    private  static int dialogType = 1;
    private View.OnClickListener onClickListener = new View.OnClickListener() {
        @Override
        public void onClick(View v) {

            switch (v.getId()) {
                case R.id.ll_close:
                    noticeDialog.dismiss();
                    break;

                case R.id.btn_chancel_notice:
//                   Boolean flag =  noticelxDialog.cb_agree.isChecked();
                    if(dialogType ==1 ) {
                        finish();
                    }else{

                    }
                    noticeDialog.dismiss();

                    break;

                case R.id.btn_save_notice:
                    if(dialogType== 1) {
                        saveData(0);
                    }
                    noticeDialog.dismiss();
                    break;

            }
        }
    };


    @Override
    public void onClick(View view) {

        String phone = "";
        String code = "";
        String pwd = "";
        switch (view.getId()) {
            case R.id.btn_login:
                //返回
//                MainActivity.start(this);
//                finish();

                break;
            case R.id.ll_phonelogin:
                PhoneLoginActivity.start(this);
                finish();
                break;
            case R.id.top_back:
//                finish();
                noticeDialog = new PublicNoticeDialog(CreateProjectDetailActivity.this,onClickListener,
                        1,"提示","暂存编辑？",
                        "否","是");
                noticeDialog.show();

                break;
            case R.id.top_mune1:
//                    GetPwdOneActivity.start(this);
                String str_debtorName = et_debtorName.getText().toString();
                if ("".equalsIgnoreCase(str_debtorName)) {
                    showToast("债务人名称不能为空", com.linkage.seapeak.utils.ToastUtil.TOAST_TYPE.WARNING);
//                    Toast.makeText(this, "债务人名称不能为空", Toast.LENGTH_SHORT).show();
                    return;
                }
                mInfo.setDebtorName(str_debtorName);
                String str_projectName = et_projectName.getText().toString();
                if ("".equalsIgnoreCase(str_projectName)) {
                    showToast("项目名称不能为空", com.linkage.seapeak.utils.ToastUtil.TOAST_TYPE.WARNING);
//                    Toast.makeText(this, "项目名称不能为空", Toast.LENGTH_SHORT).show();
                    return;
                }

                if (protype == -1) {
                    showToast("请选择项目类型", com.linkage.seapeak.utils.ToastUtil.TOAST_TYPE.WARNING);
//                    Toast.makeText(this, "请选择项目类型", Toast.LENGTH_SHORT).show();
                    return;
                }
                mInfo.setProjectName(str_projectName);
                mInfo.setProjectType(protype + "");

                String strLogo = "";
                for (int i = 0; i < mImgList.size(); i++) {
                    if (TextUtils.equals(mImgList.get(i).getFilename(), NAME_ADD)) {
                        continue;
                    }
                    strLogo = mImgList.get(i).getFilepath();
                }


                mInfo.setProjectLogo(strLogo);

                String str_et_projectNote = et_projectNote.getText().toString();
                mInfo.setProjectNote(str_et_projectNote);
                CreateProjectDetailTwoActivity.start(this, mInfo, m_addtype);
                finish();
                break;
            case R.id.top_mune2:

                saveData(0);
                break;
            case R.id.rl_addlogo:
                pickAndUploadPic(mImgList, adapter);
//                    showPopupWindow();
//                    ll_popup.startAnimation(AnimationUtils.loadAnimation(
//                            CreateProjectDetailActivity.this, R.anim.activity_translate_in));
//                    pop.showAtLocation(view, Gravity.BOTTOM, 0, 0);
                break;
            default:
                break;
        }


    }

    public void saveData(int type) {

        if (BankruptcyApp.tokeninfo == null || BankruptcyApp.tokeninfo.getToken() == null) {
            getToken();
            return;
        }

        OkHttpClient okHttpClient = new OkHttpClient();
        HashMap<String, String> params = new HashMap<String, String>();
        Random random = new Random();
        String rom = random.nextLong() + "";
        String timestamp = System.currentTimeMillis() + "";

        String str_debtorName = et_debtorName.getText().toString();
        if ("".equalsIgnoreCase(str_debtorName)) {
            showToast("债务人名称不能为空", com.linkage.seapeak.utils.ToastUtil.TOAST_TYPE.WARNING);
//            ToastUtil.showShort("债务人名称不能为空");
//            Toast.makeText(this, "债务人名称不能为空", Toast.LENGTH_SHORT).show();
            return;
        }
        if (protype == -1) {
//            ToastUtil.showShort("请选择项目类型");
            showToast("请选择项目类型", com.linkage.seapeak.utils.ToastUtil.TOAST_TYPE.WARNING);
//            Toast.makeText(this, "请选择项目类型", Toast.LENGTH_SHORT).show();
            return;
        }

        mInfo.setDebtorName(str_debtorName);
        String str_projectName = et_projectName.getText().toString();
        if ("".equalsIgnoreCase(str_projectName)) {
//            ToastUtil.showShort("项目名称不能为空");
            showToast("项目名称不能为空", com.linkage.seapeak.utils.ToastUtil.TOAST_TYPE.WARNING);
//            Toast.makeText(this, "项目名称不能为空", Toast.LENGTH_SHORT).show();
            return;
        }


        shapeLoadingDialog.setLoadingText("提交信息中...");
        shapeLoadingDialog.setCanceledOnTouchOutside(false);
        shapeLoadingDialog.show();
        mInfo.setProjectName(str_projectName);
//        String str_projectLogo  = et_projectLogo.getText().toString();

        String str_projectLogo =  "";
        for (int i = 0; i < mImgList.size(); i++) {
            if (TextUtils.equals(mImgList.get(i).getFilename(), NAME_ADD)) {
                continue;
            }
            str_projectLogo = mImgList.get(i).getFilepath();
        }

        mInfo.setProjectLogo(str_projectLogo);

        String str_projectNote = et_projectNote.getText().toString();
        mInfo.setProjectNote(str_projectNote);


        mInfo.setProjectStatus("0");
        mInfo.setProjectType(protype + "");
        mInfo.setPublicSection("0,1,2");


//        mInfo.setManagerListStr(strtmp);
        String sign = SignUtil.createSign(Consts.APPKEY, params);
        String userToken = SPUtils.getInstance(Consts.SPNAME).getString("userToken", "");

        RequestBody requestBody = new FormBody.Builder()
                .add("appid", "1000000001")
                .add("nonce", rom)
                .add("timestamp", timestamp)
                .add("token", BankruptcyApp.tokeninfo.getToken())
                .add("userToken", userToken)
//                .add("appVersion", "0.0.1")

                .add("addRole", mInfo.getAddRole())
                .add("id", mInfo.getId())
                .add("debtorName", mInfo.getDebtorName())
                .add("projectStatus", mInfo.getProjectStatus())
                .add("projectType", mInfo.getProjectType())
                .add("projectName", mInfo.getProjectName())
                .add("projectLogo", mInfo.getProjectLogo())
                .add("projectNote", mInfo.getProjectNote())
                .add("courtName", mInfo.getCourtName())
                .add("caseNumber", mInfo.getCaseNumber())
                .add("debtorLegalRepresentative", mInfo.getDebtorLegalRepresentative())
                .add("sysAddressId", mInfo.getSysAddressId())
                .add("publicStatus", "1")
                .add("publicSection", mInfo.getPublicSection())
                .add("close", mInfo.getClose())
                .add("allowJoin", mInfo.getAllowJoin())
                .add("closeClaimFiling", mInfo.getCloseClaimFiling())
                .add("openDiscussion", mInfo.getOpenDiscussion())
                .add("allowCreditorsChangInfo", mInfo.getAllowCreditorsChangInfo())
                .add("displayedInstantly", mInfo.getDisplayedInstantly())
                .add("creditorsVisibleDetails", mInfo.getCreditorsVisibleDetails())
                .add("openAdministratorList", mInfo.getOpenAdministratorList())

                .add("openAdministratorInfo", mInfo.getOpenAdministratorInfo())
                .add("openCreditorsList", mInfo.getOpenCreditorsList())
                .add("openCreditorsInfo", mInfo.getOpenCreditorsInfo())

                .add("managerListStr", mInfo.getManagerListStr())
                .add("debtorYyzzFileListStr", mInfo.getDebtorYyzzFileListStr())
                .add("courtSlwsFileListStr", mInfo.getCourtSlwsFileListStr())
                .add("courtManagerFileListStr", mInfo.getCourtManagerFileListStr())
                .add("otherFileListStr", mInfo.getOtherFileListStr())


                .build();

        String url = Consts.WEBURL_ADDPRO;

        if (!"".equalsIgnoreCase(mInfo.getId())) {
            url = Consts.WEBURL_UPDATEPRO;
        }

        Request request = new Request.Builder()
                .url(url)
                .post(requestBody)
                .build();

        okHttpClient.newCall(request).enqueue(new Callback() {
            @Override
            public void onFailure(Call call, IOException e) {
//                Log.d(TAG, "onFailure: " + e.getMessage());
                shapeLoadingDialog.dismiss();
            }

            @Override
            public void onResponse(Call call, Response response) throws IOException {
//                Log.d(TAG, response.protocol() + " " +response.code() + " " + response.message());
                shapeLoadingDialog.dismiss();
                String str = response.body().string();
                try {
                    final JSONObject object = new JSONObject(str);
                    if (object.optInt("code") == 0) {

                        runOnUiThread(new Runnable() {

                            @Override
                            public void run() {
                                //更新UI
                                Toast.makeText(CreateProjectDetailActivity.this,
                                        "提交成功", Toast.LENGTH_SHORT).show();
                                EventBus.getDefault().post(mInfo);
                                finish();

                            }

                        });
                    } else {
                        runOnUiThread(new Runnable() {

                            @Override
                            public void run() {
                                //更新UI
                                Toast.makeText(CreateProjectDetailActivity.this,
                                        "提交失败:" + object.optString("msg"), Toast.LENGTH_SHORT).show();


                            }

                        });
                    }

                    str = "";
                } catch (Exception ex) {

                    ex.printStackTrace();
                }
            }
        });


    }


    private void initWidget() {
        FullyGridLayoutManager manager = new FullyGridLayoutManager(this, 3, GridLayoutManager.VERTICAL, false);
        mRecyclerView.setLayoutManager(manager);
        adapter = new GridImagesAdapter(this, TYPE_EDIT,false);
        adapter.setList(mImgList);
        adapter.setSelectMax(maxSelectNum);
        mRecyclerView.setAdapter(adapter);
    }

    PopupWindow pop;
    LinearLayout ll_popup;

    public void showPopupWindow() {
        pop = new PopupWindow(CreateProjectDetailActivity.this);
        View view = getLayoutInflater().inflate(R.layout.item_popupwindows,
                null);
        ll_popup = (LinearLayout) view.findViewById(R.id.ll_popup);
        pop.setWidth(ViewGroup.LayoutParams.MATCH_PARENT);
        pop.setHeight(ViewGroup.LayoutParams.WRAP_CONTENT);
        pop.setBackgroundDrawable(new BitmapDrawable());
        pop.setFocusable(true);
        pop.setOutsideTouchable(true);
        pop.setContentView(view);
        RelativeLayout parent = (RelativeLayout) view.findViewById(R.id.parent);
        Button bt1 = (Button) view.findViewById(R.id.item_popupwindows_camera);
        Button bt2 = (Button) view.findViewById(R.id.item_popupwindows_Photo);
        Button bt3 = (Button) view.findViewById(R.id.item_popupwindows_cancel);
        parent.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                pop.dismiss();
                ll_popup.clearAnimation();
            }
        });
        bt1.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                try {
                    Intent camera = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
                    startActivityForResult(camera, 1);
                    pop.dismiss();
                    ll_popup.clearAnimation();
                } catch (Exception ex) {
                    ex.printStackTrace();
                }
            }
        });
        bt2.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                Intent picture = new Intent(
                        Intent.ACTION_PICK,
                        android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
                startActivityForResult(picture, 2);
                pop.dismiss();
                ll_popup.clearAnimation();
            }
        });
        bt3.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                pop.dismiss();
                ll_popup.clearAnimation();
            }
        });
    }

    @Override
    public void imageSizeChange(int size) {
//        rl_addlogo.setVisibility(size == 0 ? View.VISIBLE : View.GONE);
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        /**
         * 图片编辑
         */
        if (requestCode == ImageShowActivity.IMAGE_REQUEST && resultCode == Activity.RESULT_OK
                && null != data) {
            ArrayList urlList = data.getStringArrayListExtra("urlList");
            mImgList.clear();
            mImgList.addAll(urlList);
            adapter.notifyDataSetChanged();
//            rl_addlogo.setVisibility(mImgList.size() == 0 ? View.VISIBLE : View.GONE);
        }
    }

    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {


        if (keyCode == KeyEvent.KEYCODE_BACK) {
//            exit();
//            return false;
            dialogType =1;
            noticeDialog = new PublicNoticeDialog(CreateProjectDetailActivity.this,onClickListener,
                    1,"提示","暂存编辑？",
                    "否","是");
            noticeDialog.show();
        }
        return super.onKeyDown(keyCode, event);
    }

    private void vName() {


//        mShapeLoadingDialog.setLoadingText("提交信息中...");
//        mShapeLoadingDialog.setCanceledOnTouchOutside(false);
//        mShapeLoadingDialog.show();
        String str_projectName = et_projectName.getText().toString();
        if ("".equalsIgnoreCase(str_projectName)) {
            Toast.makeText(this, "项目名称不能为空", Toast.LENGTH_SHORT).show();
            return;
        }

        Observable<JsonObject> observable;

            observable = Network
                    .getAPIService()
                    .vName( str_projectName);


        observable
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new BaseSubscriber<JsonObject>() {
                    @Override
                    public void onNext(JsonObject json) {

                        int code = json.get("code").getAsInt();
                        if (code != 0) {
                            super.onNext(json);
                            return;
                        }
                        JsonObject objdata = json.getAsJsonObject("data");
                        Boolean flag = objdata.get("returnFlag").getAsBoolean();
                        if (flag)
                        {
                            dialogType =2;
                            noticeDialog = new PublicNoticeDialog(CreateProjectDetailActivity.this,onClickListener,
                                    5,"系统已有重名项目！","如您是法院指定的项目管理人，请继续创建，" +
                                    "\n" +
                                    "如有疑问可联系平台客服处理。",
                                    "否","继续创建");
                            noticeDialog.show();
                        }

                    }

                    @Override
                    public void onCompleted() {
                        super.onCompleted();
                    }

                    @Override
                    public void onError(Throwable e) {
                        mShapeLoadingDialog.dismiss();
                        super.onError(e);
                    }
                });

    }
}

